package org.whuims.core.utils;

import java.sql.Connection;
import java.sql.DriverManager;

public class Mysql {
    public static final String HOST = "202.114.70.53";
    public static final String PORT = "3306";
    public static final String DRIVER = "com.mysql.jdbc.Driver";
    public static final String USERNAME = "root";
    public static final String PASSWORD = "irlab2013";

    public static Connection getConn(String databaseName) {
        try {
            Class.forName(DRIVER).newInstance();
            return DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + databaseName + "?user="
                    + USERNAME + "&password=" + PASSWORD + "&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Connection getConn(String host, String databaseName, String userName, String passWord) {
        try {
            Class.forName(DRIVER).newInstance();
            return DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + databaseName + "?user=" + userName
                    + "&password=" + passWord + "&useUnicode=true&characterEncoding=utf-8");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
